package com.jxust.debate.util;

public class CommonResult<T> {

    /**
     * 返回成功失败标示
     */
    private int code;

    /**
     * 返回成功失败信息
     */
    private String message;

    /**
     * 返回成功失败附加数据
     */
    private T data;

    public CommonResult() {
    }

    public CommonResult(int code) {
        super();
        this.code = code;
    }

    public CommonResult(int code, String message) {
        super();
        this.code = code;
        this.message = message;
    }

    public CommonResult(String message, T data) {
        super();
        this.message = message;
        this.data = data;
    }

    public CommonResult(int code, String message, T data) {
        super();
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setResultEnum(ResultEnum resultEnum){
        this.setCode(resultEnum.getCode());
        this.setMessage(resultEnum.getMessage());
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> CommonResult<T> success() {
        return new CommonResult<T>(Resultcode.SUCCESS);
    }

    public static <T> CommonResult<T> success(String message) {
        return new CommonResult<T>(Resultcode.SUCCESS, message);
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<T>(Resultcode.SUCCESS, "", data);
    }

    public static <T> CommonResult<T> success(String message, T data) {
        return new CommonResult<T>(Resultcode.SUCCESS, message, data);
    }

    public static <T> CommonResult<T> fail() {
        return new CommonResult<T>(Resultcode.FAIL);
    }

    public static <T> CommonResult<T> fail(String message) {
        return new CommonResult<T>(Resultcode.FAIL, message);
    }

    public static <T> CommonResult<T> fail(int code, String message) {
        return new CommonResult<T>(code, message);
    }

    public static <T> CommonResult<T> fail(String message, T data) {
        return new CommonResult<T>(Resultcode.FAIL, message, data);
    }

    public static <T> CommonResult<T> fail(int code, String message, T data) {
        return new CommonResult<T>(code, message, data);
    }


    public static class Resultcode {
        public static final int SUCCESS = 101;

        public static final int FAIL = 100;
    }

}